#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\models\marketmodels\multiproduct.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

#undef HANDLE
#undef ABSTRACT
#define STRUCT
namespace Cephei { namespace QL { namespace Models { namespace Marketmodels {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IMarketModelMultiProductCashFlow
	public ref class CMarketModelMultiProductCashFlow : 
            public System::MarshalByRefObject,
            public Cephei::QL::Models::Marketmodels::IMarketModelMultiProductCashFlow
	{
	protected: 
		boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>* _ppMarketModelMultiProductCashFlow;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>* _phMarketModelMultiProductCashFlow;
#endif
		Object^ _MarketModelMultiProductCashFlowOwner;     // reference to object that manages the storage for this object
	internal:
		CMarketModelMultiProductCashFlow (UInt64 TimeIndex, Double Amount);
		CMarketModelMultiProductCashFlow ();
        CMarketModelMultiProductCashFlow (boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>& childNative, Object^ owner);
        CMarketModelMultiProductCashFlow (QuantLib::MarketModelMultiProductCashFlow& childNative, Object^ owner);
        CMarketModelMultiProductCashFlow (CMarketModelMultiProductCashFlow^ copy);
        CMarketModelMultiProductCashFlow (System::Type^ t);
#ifdef STRUCT
        CMarketModelMultiProductCashFlow (QuantLib::MarketModelMultiProductCashFlow childNative);
#endif       
#ifdef HANDLE
		CMarketModelMultiProductCashFlow (QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>& childNative, Object^ owner);
		CMarketModelMultiProductCashFlow (QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow> childNative);
#endif
		virtual ~CMarketModelMultiProductCashFlow ();
		!CMarketModelMultiProductCashFlow ();

	internal:
		QuantLib::MarketModelMultiProductCashFlow& GetReference ();
		boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>& GetShared ();
		QuantLib::MarketModelMultiProductCashFlow* GetPointer ();
        void SetMarketModelMultiProductCashFlow (boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow> native)
        {
            if (_ppMarketModelMultiProductCashFlow != NULL)
                delete _ppMarketModelMultiProductCashFlow;
            _ppMarketModelMultiProductCashFlow = new boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IMarketModelMultiProductCashFlow Vector interface
	ref class CMarketModelMultiProductCashFlowVector : public System::MarshalByRefObject,  
							    public INativeVector<IMarketModelMultiProductCashFlow^>,
							    public INativeVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::MarketModelMultiProductCashFlow>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CMarketModelMultiProductCashFlowVector ();
#ifdef STRUCT
		CMarketModelMultiProductCashFlowVector (std::vector<QuantLib::MarketModelMultiProductCashFlow>& vec, Object^ owner);
		CMarketModelMultiProductCashFlowVector (std::vector<QuantLib::MarketModelMultiProductCashFlow> vec);
#endif       
		CMarketModelMultiProductCashFlowVector (std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>& vec, Object^ owner);
#ifdef HANDLE
		CMarketModelMultiProductCashFlowVector (std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>& vec, Object^ owner);
#endif
		virtual ~CMarketModelMultiProductCashFlowVector ();
		!CMarketModelMultiProductCashFlowVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IMarketModelMultiProductCashFlow^ default[int] 
		{
			virtual IMarketModelMultiProductCashFlow^ get (int index) = INativeVector<IMarketModelMultiProductCashFlow^>::default::get;
			virtual void set (int index, IMarketModelMultiProductCashFlow^ value) = INativeVector<IMarketModelMultiProductCashFlow^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Generic::ICell<Cephei::QL::Models::Marketmodels::IMarketModelMultiProductCashFlow^>^ CItem[int] 
		{
			virtual Generic::ICell<IMarketModelMultiProductCashFlow^>^ get (int index) = INativeVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>::default::get;
			virtual void set (int index, Generic::ICell<IMarketModelMultiProductCashFlow^>^ value) = INativeVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::MarketModelMultiProductCashFlow>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IMarketModelMultiProductCashFlow Matrix interface
	ref class CMarketModelMultiProductCashFlowMatrix : public System::MarshalByRefObject,  
								public INativeMatrix<IMarketModelMultiProductCashFlow^>,
							    public INativeMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>
	{
	private:
#ifdef STRUCT
        std::vector<std::vector<QuantLib::MarketModelMultiProductCashFlow>>* _pVValue;
#endif       
		std::vector<std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>>* _pVBoost;
#ifdef HANDLE
		std::vector<std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner
	internal:
		CMarketModelMultiProductCashFlowMatrix ();
#ifdef STRUCT        
		CMarketModelMultiProductCashFlowMatrix (std::vector<std::vector<QuantLib::MarketModelMultiProductCashFlow>>& vec, Object^ owner);
		CMarketModelMultiProductCashFlowMatrix (std::vector<std::vector<QuantLib::MarketModelMultiProductCashFlow>> vec);
#endif        
		CMarketModelMultiProductCashFlowMatrix (std::vector<std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>>& vec, Object^ owner);
#ifdef HANDLE
		CMarketModelMultiProductCashFlowMatrix (std::vector<std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>>& vec, Object^ owner);
#endif
		virtual ~CMarketModelMultiProductCashFlowMatrix ();
		!CMarketModelMultiProductCashFlowMatrix ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property Cephei::QL::Models::Marketmodels::IMarketModelMultiProductCashFlow^ default[int, int] 
		{
			virtual IMarketModelMultiProductCashFlow^ get (int x, int y) = INativeMatrix<IMarketModelMultiProductCashFlow^>::default::get;
			virtual void set (int x, int y, IMarketModelMultiProductCashFlow^ value) = INativeMatrix<IMarketModelMultiProductCashFlow^>::default::set;
		}

		property Generic::ICell<Cephei::QL::Models::Marketmodels::IMarketModelMultiProductCashFlow^>^ CItem[int, int] 
		{
			virtual Generic::ICell<IMarketModelMultiProductCashFlow^>^ get (int x, int y) = INativeMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>::default::get;
			virtual void set (int x, int y, Generic::ICell<IMarketModelMultiProductCashFlow^>^ value) = INativeMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>::default::set;
		}

	internal:
#ifdef STRUCT
        std::vector<std::vector<QuantLib::MarketModelMultiProductCashFlow>>& GetReference ();
#endif        
		std::vector<std::vector<boost::shared_ptr<QuantLib::MarketModelMultiProductCashFlow>>>& GetShared ();

#ifdef HANDLE
		std::vector<std::vector<QuantLib::Handle<QuantLib::MarketModelMultiProductCashFlow>>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	public:
		virtual INativeVector<IMarketModelMultiProductCashFlow^>^ CreateVector () = INativeMatrix<IMarketModelMultiProductCashFlow^>::CreateVector;
	public:
		virtual INativeVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^ CreateCellVector () = INativeMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>::CreateVector;
	};

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CMarketModelMultiProductCashFlow_Factory : public System::MarshalByRefObject,  public IMarketModelMultiProductCashFlow_Factory
	{
	public:
        virtual IMarketModelMultiProductCashFlow^ Create (UInt64 TimeIndex, Double Amount);
        virtual IMarketModelMultiProductCashFlow^ Create ();
        /* <summary> Create a hybrid Matrix of IMarketModelMultiProductCashFlow, with event notification of changes </summary> */
        virtual Cephei::IMatrix<IMarketModelMultiProductCashFlow^>^ CreateMatrix();
        /* <summary> Create a hybrid Matrix of ICell of IMarketModelMultiProductCashFlow, with event notification of changes </summary> */
        virtual Generic::ICell<Cephei::IMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^>^ CreateCellMatrix();
        virtual Cephei::IMatrix<IMarketModelMultiProductCashFlow^>^ CreateMatrix(System::Collections::Generic::IEnumerable<Cephei::IVector<IMarketModelMultiProductCashFlow^>^>^ source);
        virtual Generic::ICell<Cephei::IMatrix<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^>^ CreateCellMatrix(System::Collections::Generic::IEnumerable<Cephei::IVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^>^ source);
        /* <summary> Create a hybrid Vector of IMarketModelMultiProductCashFlow, with event notification of changes </summary> */
        virtual Cephei::IVector<IMarketModelMultiProductCashFlow^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IMarketModelMultiProductCashFlow, with event notification of changes </summary> */
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^>^ CreateCellVector();
        virtual Cephei::IVector<IMarketModelMultiProductCashFlow^>^ CreateVector(System::Collections::Generic::IEnumerable<IMarketModelMultiProductCashFlow^>^ source);
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^>^ CreateCellVector(System::Collections::Generic::IEnumerable<Generic::ICell<IMarketModelMultiProductCashFlow^>^>^ source);
    };
   
/*Cephei*/ } /*QL*/ } /*Models*/ } /*Marketmodels */}
